package com.ifengchao.dao.impl;

import com.ifengchao.commonUtil.DaoException;
import com.ifengchao.dao.IBatisBaseDao1;
import com.ifengchao.dao.IBatisBaseDao2;
import com.ifengchao.dao.IBatisBaseDao3;
import com.ifengchao.dao.iface.DealOrderDao;
import com.ifengchao.pojo.AdverHourBean;
import com.ifengchao.pojo.Order;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 订单处理dao
 * @author chen
 *
 */
@Repository
public class DealOrderDaoImpl implements DealOrderDao {

	private static final Logger logger = Logger.getLogger(DealOrderDaoImpl.class);
	
	@Autowired(required=true)
	private IBatisBaseDao1 iBatisBaseDao1;
	
	@Autowired(required=true)
	private IBatisBaseDao2 iBatisBaseDao2;

	@Autowired(required=true)
	private IBatisBaseDao3 iBatisBaseDao3;

	/**
	 * 查询所有订单
	 */
	@Override
	public List<Order> queryAllOrder() throws DaoException {
		logger.info("查询所有订单");
		List<Order> userList = iBatisBaseDao1.getSqlMapClientTemplate().queryForList("dealOrderSql.queryAllOrder");
		return userList;
	}

	/**
	 * 查询所有订单
	 */
	@Override
	public List<String> queryAllPlan() throws DaoException {
		logger.info("查询所有智子云广告主");
		List<String> advterIdList = iBatisBaseDao1.getSqlMapClientTemplate().queryForList("dealOrderSql.queryAllPlan");
		return advterIdList;
	}

	/**
	 * 记录所有订单
	 */
	@Override
	public void insertPlanList(AdverHourBean insertParam) throws DaoException {
		logger.info("记录所有订单");
		try {
//			iBatisBaseDao1.getSqlMapClientTemplate().insert("dealPlatformSql.insertPlatform", entity);
			iBatisBaseDao1.getSqlMapClientTemplate().insert("dealOrderSql.insertPlanList",insertParam);
		} catch (Exception e) {
			logger.error("记录所有订单出错>>>>>>>>>",e);
			throw new DaoException(e.getMessage());
		}
	}

	/**
	 * 查询所有订单
	 */
	@Override
	public String selAdvertiseId(String zzyplanId) throws DaoException {
		logger.info("查询所有计划");
		Object advertiseId = iBatisBaseDao1.getSqlMapClientTemplate().queryForObject("dealOrderSql.queryAdvertiseId",zzyplanId);
		if(null != advertiseId) {
			return advertiseId.toString();
		} else {
			return "";
		}
	}

	/**
	 * 根据广告主id查询广告主信息
	 */
	@Override
	public Map<String,Object> selAdvertiseMsg(String advertiseId) throws DaoException {
		logger.info("查询所有计划");
		return (Map<String,Object>) iBatisBaseDao3.getSqlMapClientTemplate().queryForObject("dealUserMessageSql.selAdvertiseMsg",advertiseId);
	}

	/**
	 * 查询所有有效智子云广告主
	 */
	@Override
	public List<String> queryAllAdvertise() throws DaoException {
		logger.info("查询所有智子云广告主");
		List<String> advterIdList = iBatisBaseDao3.getSqlMapClientTemplate().queryForList("dealUserMessageSql.queryAllAdvertise");
		return advterIdList;
	}
}
